import {
  Button,
  Checkbox,
  DatePicker,
  Form,
  Icon,
  ImgDefault,
  Input,
  message,
  Modal,
  Popover,
  Select,
  Space,
  Spin,
  Switch,
  Table
} from "@bytedance/mona-ui"
import type { ColumnProps } from "@bytedance/mona-ui/es/components/table"
import React, {
  forwardRef,
  useEffect,
  useImperativeHandle,
  useState
} from "react"

import { useAppDispatch, useAppSelector } from "~store"
import { getProductList } from "~store/controller/autoCounps"

import {
  checkPromotionNewPipeal,
  getProdectListFun,
  getProductListWork
} from "./couponFunc"

const { Option } = Select
const { RangePicker } = DatePicker
const { TextArea } = Input
let allGoodsConter: any = []
let aloComter
function GoodsTable(props, ref) {
  useImperativeHandle(ref, () => ({
    getSelectGoods,
    getProdectListFunAs
  }))
  const {
    addCouponConfig,
    couponTableDataShop,
    autoStatus = false,
    isLock = false,
    selectGoodsList = []
  } = props
  const shechInfoData = {
    // check_status: '',
    check_status: "3",
    business_type: "",
    // order_field: '',
    order_field: "audit_time",
    sku_price_min: "",
    sku_price_max: "",
    sell_num_min: "",
    sell_num_max: "",
    start_time: "",
    end_time: "",
    page: 0,
    pageSize: 20,
    is_online: 1,
    createdGoodsTime: [],
    is_offline: "",
    id_name_code: "",
    show_is_select: false,
    show_select_good: false
  }
  const [shearData, setShearData] = useState<any>(shechInfoData)
  const [inputGoodsIds, setInputGoodsIds] = useState("")
  const [isGetGoodsIds, setIsGetGoodsIds] = useState(false)
  const [goodsLoading, setGoodsLoading] = useState(false)

  // 商品列表
  const [goodsListData, setGoodsListData] = useState<any>([])
  const [goodsDataInfoCont, setGoodsDaraInfoCont] = useState({ total: 0 })
  // const [addCouponList, setAddCouponList] = useState(false)
  const [indeterminateGoders, setIndeterminateGoders] = useState(false)
  const [selectAllConter, setSelectAllConter] = useState(false)
  const [selectGoodsKeys, setSelectGoodsKeys] = useState<React.Key[]>([])
  const [stopLodingFun, setStopLodingFun] = useState(false)
  const [stopLodinInfos, setStopLodinInfos] = useState(null)
  // const [stoploginStauts, setStopLodinStatus] = useState(false)
  const getprodectStatus: any = useAppSelector(
    (state) => state.autoCounps.getprodectStatus
  )
  const peodecuList: any = useAppSelector(
    (state) => state.autoCounps.peodecuList
  )

  useEffect(() => {
    // console.log('peodecuList', peodecuList)
    if (goodsListData.length && peodecuList.length) {
      // console.log('有的数据')
      goodsListData.forEach((item) => {
        const datayetr = peodecuList.find((res: any) => {
          return res.product_id === item.product_id
        })
        if (datayetr) {
          item.product_deteil = datayetr
        }
      })
      setGoodsListData([...goodsListData])
    }
  }, [peodecuList])

  let cletaerDtae
  // let stopStatus = false
  const [pageSize, setPageSize] = useState(50)
  const inputRef = React.useRef<any>(null)

  useEffect(() => {
    // console.log('修改的数据')
    if (aloComter !== couponTableDataShop) {
      aloComter = couponTableDataShop
      if (aloComter.length) {
        const getSetInterData = aloComter[0]
        // console.log('getSetInterData', getSetInterData)
        if (goodsListData && goodsListData.length) {
          // 直接处理 不需要重新请求
          setGoodsLoading(true)
          checkPromotionNewPipeal(
            getSetInterData,
            addCouponConfig,
            goodsListData
          ).then((res) => {
            // console.log('rererer', res)
            setGoodsLoading(false)
            setGoodsListData([...res])
            setSelectGoodsKeys(
              res
                .filter((ress: any) => {
                  return ress.chrackData.check_pass
                })
                .map((resa: any) => resa.product_id || null)
            )
          })
        } else {
          getProdectListFunAs()
        }
      }
    }
  }, [couponTableDataShop])
  useEffect(() => {
    if (isGetGoodsIds) {
      inputRef.current?.focus({
        cursor: "end"
      })
    } else {
      inputRef.current?.blur()
    }
  }, [isGetGoodsIds])
  useEffect(() => {
    if (!selectGoodsKeys || !selectGoodsKeys.length) {
      setSelectAllConter(false)
      setIndeterminateGoders(false)
      return
    }
    const allSelected = goodsListData
      .filter((res) => res.chrackData.check_pass)
      .every((selectAlls) => selectGoodsKeys.includes(selectAlls.product_id))
    console.log("allSelected", allSelected)
    if (!allSelected) {
      setIndeterminateGoders(true)
      setSelectAllConter(false)
      return
    }
    // let noSeleCtalls = false
    // goodsListData.forEach(selectAlls => {
    //     if(!selectGoodsKeys.includes(selectAlls.product_id)) {
    //         noSeleCtalls = true
    //     }
    // })
    // if(noSeleCtalls) {
    //     setIndeterminateGoders(false)
    //     setSelectAllConter(false)
    //     return
    // }
    // if (selectGoodsKeys.length === goodsListData.filter(res => res.chrackData.check_pass).length) {
    //     setSelectAllConter(true)
    //     setIndeterminateGoders(false)
    //     return
    // }
    setSelectAllConter(true)
    setIndeterminateGoders(false)
  }, [selectGoodsKeys, goodsListData])
  // useEffect(() => {
  //     if (shearData == shechInfoData) {
  //         // getProdectListFunAs()
  //     }
  //     // if (shearData.order_field === '' || shearData.order_field === 'audit_time' || shearData.order_field === 'offline_time') {
  //     //     getProdectListFunAs()
  //     // }
  // }, [shearData])
  interface ColumnPropsType {
    index: number
    name: string
  }
  const onSelectGoodsKeysChange = (newSelectedRowKeys: React.Key[]) => {
    // console.log('newSelectedRowKeys', newSelectedRowKeys, selectGoodsKeys)
    const noSelects = []
    goodsListData.forEach((res) => {
      if (!newSelectedRowKeys.includes(res.product_id)) {
        noSelects.push(res.product_id)
      }
    })
    const allAdds = selectGoodsKeys.filter((res) => !noSelects.includes(res))
    newSelectedRowKeys.forEach((res) => {
      if (!selectGoodsKeys.includes(res)) {
        allAdds.push(res)
      }
    })
    setSelectGoodsKeys(allAdds)
  }
  const dispacth = useAppDispatch()
  function copyToClipboard(text) {
    navigator.clipboard
      .writeText(text)
      .then(function () {
        message.success("复制成功")
      })
      .catch(function (err) {
        message.error("复制失败")
      })
  }
  const goodsTitle: ColumnProps<ColumnPropsType>[] = [
    {
      title: "商品信息",
      key: "11",
      // dataIndex: 'product_id',
      align: "left",
      // ellipsis: true,
      width: 280,
      render: (text: any, record: any) => {
        // function TilpDater(content) {
        //     const texts = content.reject_reason

        //     return <div></div>
        // }
        return (
          <Space direction="vertical">
            <Space>
              <ImgDefault
                imgSrc={(() => {
                  const imgae = record.img.replace("obj/", "")
                  return imgae + "~110x110_q75.image"
                })()}
                mask={false}
                width={60}
                height={60}></ImgDefault>
              <Space direction="vertical" size={4}>
                <div
                  className="title"
                  style={{
                    fontSize: 12,
                    color: "#252931"
                  }}>
                  {record.name}
                </div>
                <div
                  className="isduer"
                  style={{
                    color: "#898b8f",
                    fontSize: 12
                  }}>
                  ID:{record.product_id}
                  <Icon
                    type="CopyIcon"
                    className="copyiconitem"
                    style={{
                      marginLeft: 5,
                      cursor: "pointer"
                      // opacity: 0,
                      // ':hover': {
                      //     color: '#1966FF'
                      // }
                    }}
                    onClick={() => copyToClipboard(record.product_id)}
                  />
                </div>
              </Space>
            </Space>
            {!record.chrackData.check_pass && (
              <div
                style={{
                  color: "red"
                }}>
                {record.chrackData.reject_reason}
                {/* {TilpDater(record.chrackData.reject_reason)} */}
              </div>
            )}
          </Space>
        )
      }
    },
    // {
    //     title: '商品ID',
    //     key: '0',
    //     dataIndex: 'product_id',
    //     align: "center",
    //     ellipsis: true
    // },
    // {
    //     title: '标题',
    //     key: '1',
    //     dataIndex: 'name',
    //     align: "center",
    //     ellipsis: true
    // },
    {
      title: "售价",
      key: "2",
      // dataIndex: 'price_lower',
      align: "center",
      ellipsis: true,
      render: (_, record: any) => {
        if (record.min_price === record.max_price) {
          return (record.min_price / 100).toFixed(2)
        }
        return `￥${(record.min_price / 100).toFixed(2)} ~ ￥${(
          record.max_price / 100
        ).toFixed(2)}`
      }
    },
    {
      title: "总库存",
      key: "3",
      dataIndex: "stock_num",
      align: "center"
    },
    {
      title: "总销量",
      key: "4",
      // dataIndex: 'sell_num',
      align: "center",
      render: (_, record: any) => {
        // 加载中的状态
        // console.log('record详情', record.product_deteil.sell_num)
        if (!record) return null
        if (!record.product_deteil) return null
        return (
          <>
            {getprodectStatus && (
              <Spin size="small" indicator={<Icon.LoadingIcon />} />
            )}
            {!getprodectStatus && <span>{record.product_deteil.sell_num}</span>}
          </>
        )
      }
    },
    {
      title: "商品创建时间",
      key: "5",
      dataIndex: "create_time",
      align: "center",
      ellipsis: true
    }
    // {
    //     title: '商品状态',
    //     key: '6',
    //     dataIndex: 'tab',
    //     align: "center",
    //     // ellipsis: true
    // },
    // {
    //     title: '操作',
    //     key: '7',
    //     // dataIndex: 'birth',
    //     align: "center",
    //     render: (_, record, index) => {
    //         return (
    //             <Icon
    //                 type="DeleteIcon" style={{
    //                     fontSize: 16,
    //                     color: 'red',
    //                     cursor: 'pointer'
    //                 }}
    //                 onClick={() => {
    //                     let setTabData = goodsScope === 1 ? couponTableDataShop : couponTableDataAll
    //                     let setTabFun = goodsScope === 1 ? setCouponTableDataShop : setCouponTableDataAll
    //                     setTabData.splice(index, 1)
    //                     setTabFun([...setTabData])
    //                 }}
    //             ></Icon>
    //         );
    //     },
    // }
  ]
  // const [shearGoodsId, setShearGoodsId] = useState(false)
  // let addcontettime
  let addLimitStop = 20
  let addInfoLimit = 0
  let getPredectListall: any[] = []

  async function getProdectListFunAs(data?) {
    const getTimetype = {
      // "validate_type": 1,
      // "participate_type": 2,
      // "activity_tool_type": 7,
      // "activity_tool_discount_type": 1,
      // "support_type": 5,
      start_time: addCouponConfig.start_apply_time,
      end_time: addCouponConfig.end_apply_time,
      indexkey: 1
    }
    setGoodsLoading(true)
    const protList = await getProductListWork([getTimetype])
    getPredectListall = protList[0].ckproduct.map((resquert) => {
      if (!resquert.chrackData) {
        resquert.chrackData = {
          check_pass: true
        }
      }
      return resquert
    })

    if (autoStatus) {
      getPredectListall.forEach((res: any) => {
        res.chrackData.check_pass = true
      })
    }
    if (aloComter && aloComter.length) {
      getPredectListall = await checkPromotionNewPipeal(
        aloComter[0],
        addCouponConfig,
        getPredectListall
      )
    }
    // 默认选择上商品
    if (!autoStatus) {
      setSelectGoodsKeys(
        getPredectListall
          .filter((res: any) => {
            // if (autoStatus && selectGoodsList.length) {
            //     return selectGoodsList.includes(res.product_id)
            // }
            return res.chrackData.check_pass
          })
          .map((res: any) => res.product_id || null)
      )
    } else {
      setSelectGoodsKeys(
        getPredectListall
          .filter((res: any) => {
            if (autoStatus && selectGoodsList.length) {
              return selectGoodsList.includes(res.product_id)
            }
            return false
          })
          .map((res: any) => res.product_id || null)
      )
    }

    // console.log('获取列表123456789', getPredectListall)
    if (getPredectListall.length && peodecuList.length) {
      // console.log('有的数据')
      getPredectListall.forEach((item) => {
        const datayetr = peodecuList.find((res: any) => {
          return res.product_id === item.product_id
        })
        if (datayetr) {
          item.product_deteil = datayetr
        }
      })
      // setGoodsListData([...goodsListData])
    }
    setGoodsListData([...getPredectListall])
    allGoodsConter = getPredectListall
    setGoodsLoading(false)
    return
    // const shearDater = JSON.parse(JSON.stringify(data || shearData))
    // setGoodsLoading(true)
    // shearDater.sku_price_max = shearDater.sku_price_max * 100 + ""
    // shearDater.sku_price_min = shearDater.sku_price_min * 100 + ""

    // delete shearDater.createdGoodsTime
    // getProdectListFun(shearDater).then((res: any) => {
    //   if (res.code) {
    //     message.error(res.msg)
    //     setGoodsLoading(false)
    //     return
    //   }
    //   getPredectListall = res.data || []
    //   if (res.total <= 700) {
    //     addLimitStop = 70
    //   }
    //   goodsDataInfoCont.total = res.total
    //   setGoodsDaraInfoCont({ ...goodsDataInfoCont })
    //   shearDater.page = 0
    //   getPredectMiter(res.total, shearDater)
    // })
  }
  let errpage: any[] = []
  function getPredectMiter(total, shearDater) {
    let stop = localStorage.getItem("stopLodingFun")
    // console.log('开始进场', stop)

    if (stop === "true") {
      // console.log('已停止加载')
      setGoodsLoading(false)
      setStopLodingFun(false)
      message.warning("已停止加载")
      localStorage.setItem("stopLodingFun", "false")
      if (cletaerDtae) {
        clearTimeout(cletaerDtae)
        cletaerDtae = null
      }
      return
    }
    // console.log('接受的')
    addInfoLimit = 1

    // 是否加载全部
    const getallData: any = []
    // console.log('shearDater', shearDater)
    // console.log('shearDater', shearDater.page)
    // console.log('shearDater', shearDater.pageSize)
    while (
      shearDater.pageSize * (shearDater.page + 1) < total &&
      addInfoLimit < addLimitStop
    ) {
      addInfoLimit += 1
      shearDater.page++
      // console.log('shearDater', shearDater
      // )
      getallData.push(getProdectListFun(shearDater))
    }

    Promise.all(getallData).then((resit) => {
      // console.log('获取全部数据', resit)

      resit.forEach((resdata) => {
        if (!resdata.code) {
          getPredectListall.push(...resdata.data)
        } else {
          errpage.push({
            config: resdata.config
          })
        }
      })
      setSelectGoodsKeys(
        getPredectListall.map((res: any) => res.product_id || null)
      )
      setGoodsListData([...getPredectListall])
      if (shearDater.pageSize * (shearDater.page + 1) < total) {
        cletaerDtae = setTimeout((_) => {
          setStopLodinInfos(shearDater)
          getPredectMiter(total, shearDater)
        }, 5000)
        // console.log('cletaerDtae', cletaerDtae)
        return
      }
      // console.log('errpage', errpage)
      localStorage.setItem("stopLodingFun", "false")
      setStopLodingFun(false)
      setStopLodinInfos(null)
      setGoodsLoading(false)
    })
  }

  const goodsSelectKeys: any = {
    columnTitle: (
      <Space direction="vertical" size={1}>
        <Checkbox
          indeterminate={indeterminateGoders}
          checked={selectAllConter}
          disabled={(() => {
            return goodsListData.filter((res) => res.chrackData.check_pass).length === 0
          })()}
          onChange={(e) => {
            console.log("e", e.target.checked)
            // console.log('goodsListData', goodsListData)
            console.log("selectGoodsList", allGoodsConter, goodsListData)
            setSelectAllConter(e.target.checked)
            if (e.target.checked) {
              // let addNewConter = []
              goodsListData.forEach((resq) => {
                if (!selectGoodsKeys.includes(resq.product_id) && resq.chrackData.check_pass) {
                  selectGoodsKeys.push(resq.product_id)
                }
                // addNewConter.push(resq.product_id)
              })

              onSelectGoodsKeysChange([...selectGoodsKeys])

              // onSelectGoodsKeysChange(goodsListData.filter(res => res.chrackData.check_pass).map((item: any) => {
              //     return item.product_id
              // }))
            } else {
              onSelectGoodsKeysChange(
                selectGoodsKeys.filter((res) => {
                  return !goodsListData.find((item) => item.product_id === res)
                })
              )
            }
          }}></Checkbox>
        <span>
          {selectGoodsKeys.length}/{allGoodsConter.length}
        </span>
      </Space>
    ),
    columnWidth: 100,
    selectedRowKeys: selectGoodsKeys,
    onChange: onSelectGoodsKeysChange,
    getCheckboxProps: (record) => ({
      disabled: !record.chrackData.check_pass
    })
  }
  const getSelectGoods = () => {
    return selectGoodsKeys
  }
  function upAddIdData(data?) {
    const interdata = data || inputGoodsIds
    // console.log('inputGoodsIds', data)

    const getKon = interdata
      .split(/[\s,， ?]/)
      .filter(
        (item: any, index, self) =>
          item &&
          !isNaN(item * 1) &&
          self.indexOf(item) === index &&
          item.length === 19
      )

    if (!getKon || !getKon.length) return message.warning("输入的ID无效!!!")
    shearData.id_name_code = getKon
    // getProdectListFunAs(shearData)
    // console.log('shearData', shearData)
    setShearData({ ...shearData })
    setIsGetGoodsIds(false)
  }

  function shearContenData() {
    // getPredectListall = protList[0].ckproduct
    console.log("到0")
    let infoter = allGoodsConter

    if (shearData.start_time && shearData.end_time) {
      infoter = infoter.filter((res) => {
        // console.log('resresres00000.....', res)
        return (
          (new Date(res?.create_time) >= new Date(shearData.start_time) &&
            new Date(res?.create_time) <= new Date(shearData.end_time)) ||
          false
        )
      })
    }

    if (shearData.sell_num_min && shearData.sell_num_max) {
      // res.price
      infoter = infoter.filter((res) => {
        if (!res.product_deteil) return false
        // console.log('res', res)
        return (
          (res.product_deteil.sell_num >= shearData.sell_num_min &&
            res.product_deteil.sell_num <= shearData.sell_num_max) ||
          false
        )
      })
    }

    if (shearData.sku_price_min && shearData.sku_price_max) {
      // res.price
      infoter = infoter.filter((res) => {
        // console.log('res', res)
        return (
          (res.price / 100 >= shearData.sku_price_min &&
            res.price / 100 <= shearData.sku_price_max) ||
          false
        )
      })
    }

    if (shearData.id_name_code || shearData.id_name_code.length) {
      if (infoter && infoter.length) {
        infoter = infoter.filter((res: any) => {
          return shearData.id_name_code.includes(res.product_id)
        })
      } else {
        infoter = allGoodsConter.filter((res) => {
          return shearData.id_name_code.includes(res.product_id)
        })
      }
    }
    //  else {

    //     infoter = infoter.length ? infoter : allGoodsConter
    // }
    if (shearData.show_select_good) {
      infoter = infoter.filter((res: any) => {
        return selectGoodsKeys.includes(res.product_id)
      })
    }

    if (shearData.show_is_select) {
      infoter = infoter.filter((res: any) => {
        return res.chrackData.check_pass
      })
    }
    console.log("infoter", infoter)
    setGoodsListData([...infoter])
    // setSelectGoodsKeys(infoter.filter((res: any) => res.chrackData.check_pass).map((res: any) => res.product_id))
    // allGoodsConter = []
  }
  useEffect(() => {
    if (shearData == shechInfoData) {
      getProdectListFunAs()
    } else {
      shearContenData()
    }
    // // if (shearData.order_field === '' || shearData.order_field === 'audit_time' || shearData.order_field === 'offline_time') {
    // //     getProdectListFunAs()
    // // }
  }, [shearData])

  return (
    <>
      <Space direction="vertical" size={6}>
        {!isLock && (
          <Form layout="inline" initialValues={shearData} name="sheaderForm">
            {/* <Form.Item label="商品范围">
                    <Select size="small"
                        value={shearData.order_field}
                        style={{
                            width: 120
                        }}
                        onChange={(e: any) => {
                            console.log('eee', e)
                            e ? shearData.business_type = '4' : shearData.business_type = ''
                            shearData.order_field = e
                            // shearData.id_name_code = ''
                            // setInputGoodsIds('')
                            // setShearGoodsId(false)
                            if (!e) {
                                shearData.is_offline = ''
                                shearData.is_online = 1
                                shearData.check_status = ''
                            }

                            if (e == 'audit_time') {
                                shearData.check_status = '3'
                                shearData.is_offline = ''
                                shearData.is_online = 1
                            }
                            if (e === 'offline_time') {
                                shearData.is_offline = '1'
                                shearData.check_status = ''
                                shearData.is_online = ''
                            }
                            if (e === 'getId') {

                                setIsGetGoodsIds(true)
                                // return
                            }
                            setShearData({ ...shearData })
                        }}
                    >
                        <Option value="">全部</Option>
                        <Option value="audit_time">售卖中</Option>
                        <Option value="offline_time">已下架</Option>
                    </Select>
                </Form.Item> */}
            <Form.Item label="商品ID">
              <Input
                size="small"
                value={inputGoodsIds}
                placeholder="可输入多个商品ID"
                allowClear
                onClick={() => {
                  setIsGetGoodsIds(true)
                }}
                onChange={(e) => {
                  console.log("e.target.value", e.target.value)
                  setInputGoodsIds(e.target.value)
                  if (!e.target.value) {
                    shearData.id_name_code = ""
                    setShearData({ ...shearData })
                    return
                  }
                  upAddIdData(e.target.value)

                  // setTimeout(() => {
                  // }, 500)
                }}></Input>
            </Form.Item>
            <Form.Item label="价格">
              <Input.Group compact size="small">
                <Input
                  wrapperStyle={{ width: 80, textAlign: "center" }}
                  placeholder="开始"
                  value={shearData.sku_price_min}
                  prefix="￥"
                  size="small"
                  onChange={(e: any) => {
                    // console.log('eee', e.target.value)
                    shearData.sku_price_min = e.target.value
                    setShearData({ ...shearData })
                  }}
                />
                <Input
                  className="site-input-split"
                  wrapperStyle={{
                    width: 30,
                    borderLeft: 0,
                    borderRight: 0,
                    pointerEvents: "none"
                  }}
                  placeholder="~"
                  disabled
                  size="small"
                />
                <Input
                  className="site-input-right"
                  wrapperStyle={{
                    width: 80,
                    textAlign: "center"
                  }}
                  value={shearData.sku_price_max}
                  prefix="￥"
                  size="small"
                  placeholder="结束"
                  onChange={(e: any) => {
                    // console.log('eee', e)
                    // console.log('eee', e.target.value)
                    shearData.sku_price_max = e.target.value
                    setShearData({ ...shearData })
                  }}
                />
              </Input.Group>
            </Form.Item>
            <Form.Item label="销量">
              <Input.Group compact size="small">
                <Input
                  wrapperStyle={{ width: 80, textAlign: "center" }}
                  placeholder="开始"
                  value={shearData.sell_num_min}
                  prefix="￥"
                  size="small"
                  onChange={(e: any) => {
                    // console.log('eee', e.target.value)
                    shearData.sell_num_min = e.target.value
                    setShearData({ ...shearData })
                  }}
                />
                <Input
                  className="site-input-split"
                  wrapperStyle={{
                    width: 30,
                    borderLeft: 0,
                    borderRight: 0,
                    pointerEvents: "none"
                  }}
                  placeholder="~"
                  disabled
                  size="small"
                />
                <Input
                  className="site-input-right"
                  wrapperStyle={{
                    width: 80,
                    textAlign: "center"
                  }}
                  value={shearData.sell_num_max}
                  prefix="￥"
                  size="small"
                  placeholder="结束"
                  onChange={(e: any) => {
                    // console.log('eee', e)
                    // console.log('eee', e.target.value)
                    shearData.sell_num_max = e.target.value
                    setShearData({ ...shearData })
                  }}
                />
              </Input.Group>
            </Form.Item>
            {/* 
                <Form.Item label="创建时间">
                    <RangePicker size="small" value={shearData.createdGoodsTime} onChange={(e) => { }} format='YYYY-MM-DD HH:mm:ss' />
                </Form.Item> */}
            <Form.Item label="创建时间">
              <RangePicker
                size="small"
                // defaultValue={[moment('2015/01/01', dateFormat), moment('2015/01/01', dateFormat)]}
                format="YYYY-MM-DD HH:mm:ss"
                value={shearData.createdGoodsTime}
                showTime={{ format: "HH:mm:ss" }}
                onChange={(e) => {
                  console.log("e", e)
                  shearData.createdGoodsTime = e
                  if (!e) {
                    shearData.start_time = ""
                    shearData.end_time = ""
                    setShearData({ ...shearData })
                    return
                  }
                  shearData.start_time = e[0].format("YYYY-MM-DD HH:mm:ss")
                  shearData.end_time = e[1].format("YYYY-MM-DD HH:mm:ss")
                  setShearData({ ...shearData })
                }}
              />
            </Form.Item>
            <Form.Item label="显示选择商品">
              <Switch
                size="small"
                checked={shearData.show_select_good}
                onChange={(e) => {
                  setShearData({ ...shearData, show_select_good: e })
                }}></Switch>
            </Form.Item>
            {/* <Form.Item label="销量">
                    <Input.Group compact size="small">
                        <Input wrapperStyle={{ width: 80, textAlign: 'center' }} placeholder="开始" size="small" value={shearData.sell_num_min} onChange={(e) => {
                            // console.log('eee', e)
                            // console.log('eee', e.target.value)
                            shearData.sell_num_min = e.target.value
                            setShearData({ ...shearData })
                        }} />
                        <Input
                            className="site-input-split"
                            wrapperStyle={{
                                width: 30,
                                borderLeft: 0,
                                borderRight: 0,
                                pointerEvents: 'none',
                            }}
                            placeholder="~"
                            disabled
                            size="small"
                        />
                        <Input
                            className="site-input-right"
                            wrapperStyle={{
                                width: 80,
                                textAlign: 'center',
                            }}
                            value={shearData.sell_num_max}
                            placeholder="结束"
                            size="small"
                            onChange={(e) => {
                                // console.log('eee', e)
                                // console.log('eee', e.target.value)
                                shearData.sell_num_max = e.target.value
                                setShearData({ ...shearData })
                            }}
                        />
                    </Input.Group>
                </Form.Item> */}
            {!autoStatus && (
              <Form.Item label="显示可用商品">
                <Switch
                  size="small"
                  checked={shearData.show_is_select}
                  onChange={(e) => {
                    setShearData({ ...shearData, show_is_select: e })
                  }}></Switch>
              </Form.Item>
            )}

            <Form.Item>
              <Space>
                <Button
                  type="primary"
                  size="small"
                  onClick={() => {
                    // getProdectListFunAs()
                  }}
                  disabled={goodsLoading}
                  loading={goodsLoading}>
                  搜索
                </Button>
                <Button
                  type="primary"
                  size="small"
                  onClick={() => {
                    getProdectListFunAs()
                  }}
                  disabled={goodsLoading}
                  loading={goodsLoading}>
                  刷新商品列表
                </Button>
                <Button
                  type="primary"
                  size="small"
                  onClick={() => {
                    dispacth(getProductList(true))
                  }}
                  disabled={goodsLoading || getprodectStatus}
                  loading={goodsLoading || getprodectStatus}>
                  刷新商品销量
                </Button>
                <Button
                  size="small"
                  onClick={() => {
                    setInputGoodsIds("")
                    setShearData({ ...shechInfoData })
                    getProdectListFunAs(shechInfoData)
                    // setTimeout(_ => {

                    // }, 0)
                  }}>
                  重置
                </Button>
                {/* {goodsLoading && <Button type="primary" size="small" danger onClick={() => {
                            message.warning('正在停止，请稍后...')
                            setStopLodingFun(true)
                            localStorage.setItem('stopLodingFun', 'true')
                            // stopStatus = true
                        }} disabled={stopLodingFun} loading={stopLodingFun}>停止加载</Button>}
                        {stopLodinInfos && <Button size="small" onClick={() => {
                            // message.warning('正在停止，请稍后...')
                            // setStopLodingFun(true)
                            // localStorage.setItem('stopLodingFun', 'true')
                            // stopStatus = true
                            setGoodsLoading(true)
                            getPredectListall = [...goodsListData]
                            getPredectMiter(goodsDataInfoCont.total, stopLodinInfos)
                        }} disabled={stopLodingFun || goodsLoading} loading={stopLodingFun || goodsLoading}>继续加载</Button>} */}
              </Space>
            </Form.Item>
          </Form>
        )}
        <Table
          loading={goodsLoading}
          locale={{
            emptyText: (
              <div>
                请加载商品列表
                <Button
                  type="link"
                  onClick={() => {
                    // setAddCouponList(true)
                    getProdectListFunAs()
                  }}>
                  加载
                </Button>
              </div>
            )
          }}
          rowKey="product_id"
          columns={goodsTitle}
          dataSource={
            !isLock
              ? goodsListData
              : goodsListData.filter((item) =>
                selectGoodsList.includes(item.product_id)
              )
          }
          bordered
          pagination={{
            pageSize: pageSize,
            // current: shearData.page + 1,
            pageSizeOptions: ["20", "50", "100", "200"],
            total: !isLock
              ? goodsListData.length
              : goodsListData.filter((item) =>
                selectGoodsList.includes(item.product_id)
              ).length,
            // onShowSizeChange: (pageSize) => {
            //     console.log('pageSize', pageSize)
            // },
            onChange: (page, pageSize: any) => {
              setPageSize(pageSize)
              // console.log('修改页', page, pageSize)
              // shearData.page = page - 1
              // shearData.pageSize = pageSize
              // setShearData({ ...shearData })
              // getProdectListFunAs(shearData)
            },

            showTotal: (total, range) => {
              return `共 ${!isLock
                ? goodsListData.length
                : goodsListData.filter((item) =>
                  selectGoodsList.includes(item.product_id)
                ).length
                } 条数据, 已加载 ${total} 条`
            }
          }}
          scroll={{ y: 480 }}
          size="small"
          rowSelection={isLock ? null : goodsSelectKeys}
        />
        <Modal
          size="small"
          visible={isGetGoodsIds}
          title="输入商品ID"
          okText=" 确定"
          cancelText=" 取消"
          bodyBottomMask
          wrapClassName={"sp-small-modal"}
          onCancel={() => {
            setIsGetGoodsIds(false)
            setInputGoodsIds("")
            shearData.id_name_code = ""
            setShearData({ ...shearData })
          }}
          onOk={() => upAddIdData()}>
          <TextArea
            placeholder="请输入本店的商品ID支持(一行一个, 逗号分隔, 空格分隔)"
            ref={inputRef}
            autoSize={{ minRows: 15, maxRows: 30 }}
            value={inputGoodsIds}
            onChange={(e: any) => {
              setInputGoodsIds(e.target.value)
            }}></TextArea>
        </Modal>
      </Space>
    </>
  )
}
export default forwardRef(GoodsTable)
